-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tsfn: implement TypedThreadSafeFunction #742
tsfn: implement TypedThreadSafeFunction #742
Conversation
Hey @gabrielschulhof , @mhdawson ... Soooo I am a little stuck now. I have no idea why this is happening, but it seems that the I did as you suggested, and migrated the old "multi-threaded" TSFN test to this new TSFNEx methodology. The changes to do so seem minimal, so I'm not sure why this is erroring. I've added this This is what I've got in my debugger: and here's the stack...
Hopefully we can discuss in today's call. |
Hi @gabrielschulhof , I took into a look into what you suggested, that maybe all threads have called I pinpointed the failure to this specific portion: // Start the thread in blocking mode, and assert that it could not finish.
// Quit early by aborting.
.then(() => testWithJSMarshaller({
threadStarter: 'startThread',
quitAfter: 1,
maxQueueSize: binding.threadsafe_function_ex_threadsafe.MAX_QUEUE_SIZE,
abort: true
}))
.then((result) => assert.strictEqual(result.indexOf(0), -1)) ... and when my So I think you are completely right: this test has the TSFN abort, so I suppose there are still items on the queue when an abort happens. So, am I correct that:
EDIT: I ask for clarification, because I want to put this in the documentation. I don't think it's inherently clear that your TSFN's "environment" is cleaned up on the last Do you know of any place where we have documentation about the "CallJS can be ran with empty napi env/function after the TSFN has been finalized, for you to process the remaining items on the queue" or whatever? |
It should actually check for empty jsCallback
From discussion in the meeting we came up with another suggestion which was |
When #832 lands, I will rebase, rename, and push. |
@KevinEady, landed #832 |
@KevinEady we suggested |
be32dc8
to
559ad8c
Compare
Hi @mhdawson , I have rebased + renamed to @gabrielschulhof / @mhdawson, can you run the CI? |
@KevinEady I'm not sure what's going on with TravisCI. We do have I checked the travis permission and found out that Node.js github org doesn't grant any public write access to travis. Not sure if it is a recent change. |
12.x - https://ci.nodejs.org/view/x%20-%20Abi%20stable%20module%20API/job/node-test-node-addon-api-new/3157/ |
12.x had a failure so re-run: https://ci.nodejs.org/view/x%20-%20Abi%20stable%20module%20API/job/node-test-node-addon-api-new/3174/ |
This was the failure on 12.x on Mac 15 Running test 'threadsafe_function/threadsafe_function_sum'
Build timed out (after 60 minutes). Marking the build as failed. |
Looks like https://ci.nodejs.org/view/x%20-%20Abi%20stable%20module%20API/job/node-test-node-addon-api-new/3174/ passed... do you think there is some issue with the original tsfn test? |
Seems like the re-run I launched was on 16.x. Another one on 12.x this time: https://ci.nodejs.org/view/x%20-%20Abi%20stable%20module%20API/job/node-test-node-addon-api-new/3175/ @KevinEady my first guess is an existing problem with the test unless somehow the PR refactored code which the base ThreadSafeFunction uses? |
Looks like this simply adds to napi-inl.h so most likely an existing flaky issue with the test. As long as the new 12.x run I launched passes I think we can land this PR. @KevinEady if you are ok to land then I think we should be good to go. |
@legendecas are you ok with this landing now? Just want to make sure as it shows requested changes, but I think that was just to close on the name change. |
@mhdawson I have no problems with that. |
@legendecas I think you can remove the -1, because the class was renamed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. This is a great work! LGTM
CI on resulting master was green: |
Implements a templated
TypedThreadSafeFunction<ContextType, DataType, Callback>
class. The class also adds static, compile-time support for the optionalFunction
argument on N-API 5+ usingstd::nullptr_t
(as well as completely missingFunction
argument) on N-API 5+.TODO:
ThreadSafeFunction
class can utilize this one, as done in previous POC tsfn: implement ThreadSafeFunctionEx for GCC 5+ #687 (comment)Fixes: